home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / AppsToGo / DTS.Draw / Colors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-22  |  3.0 KB  |  123 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        Colors.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19.  
  20.  
  21. /*****************************************************************************/
  22.  
  23.  
  24.  
  25. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  26. #include "App.defs.h"        /* Get various application definitions.            */
  27. #include "App.protos.h"        /* Get the prototypes for the application.        */
  28.  
  29. #ifndef __PICKER__
  30. #include <Picker.h>
  31. #endif
  32.  
  33. #ifndef __TREEOBJ2__
  34. #include "TreeObj2.h"
  35. #endif
  36.  
  37. extern RGBColor    gBorderColor, gContentColor;
  38.  
  39.  
  40.  
  41. /*****************************************************************************/
  42. /*****************************************************************************/
  43.  
  44. #ifdef applec
  45. #pragma segment DTSDrawSeg1
  46. #endif
  47.  
  48. /*****************************************************************************/
  49. /*****************************************************************************/
  50.  
  51.  
  52.  
  53. OSErr    ChangeColor(FileRecHndl frHndl, WindowPtr window, short part)
  54. {
  55. #ifndef __MWERKS__
  56. #pragma unused (window)
  57. #endif
  58.  
  59.     short            i;
  60.     TreeObjHndl        root, cobj;
  61.     RGBColor        rgb, rgb2;
  62.     Boolean            gotColor;
  63.     static Point    minus1Org = {-1, -1};
  64.  
  65.     rgb = (part == kBorderColor) ? gBorderColor : gContentColor;
  66.     gotColor = false;
  67.  
  68.     root = (*frHndl)->d.doc.root;
  69.     for (i = (*root)->numChildren; i;) {
  70.         cobj = GetChildHndl(root, --i);
  71.         if (DoTreeObjMethod(cobj, GETSELECTMESSAGE, 0)) {
  72.             if ((*cobj)->type < GROUPOBJ) {
  73.                 rgb2 = (part == kBorderColor) ? mDerefCommon(cobj)->borderColor :
  74.                                                 mDerefCommon(cobj)->contentColor;
  75.                 if (!gotColor) {
  76.                     gotColor = true;
  77.                     rgb = rgb2;
  78.                     continue;
  79.                 }
  80.                 if (
  81.                     (rgb.red   != rgb2.red)   ||
  82.                     (rgb.green != rgb2.green) ||
  83.                     (rgb.blue  != rgb2.blue)
  84.                 ) {
  85.                     switch (part) {
  86.                         case kBorderColor:
  87.                             rgb.red = rgb.green = rgb.blue = 0;
  88.                             break;
  89.                         case kContentColor:
  90.                             rgb.red = rgb.green = rgb.blue = 0xFFFF;
  91.                             break;
  92.                     }
  93.                 }
  94.             }
  95.         }
  96.     }
  97.  
  98.     if (GetColor(minus1Org, "\p", &rgb, &rgb2)) {
  99.         if (part == kBorderColor)
  100.             gBorderColor = rgb2;
  101.         else
  102.             gContentColor = rgb2;
  103.         for (i = (*root)->numChildren; i;) {
  104.             cobj = GetChildHndl(root, --i);
  105.             if (DoTreeObjMethod(cobj, GETSELECTMESSAGE, 0)) {
  106.                 if ((*cobj)->type < GROUPOBJ) {
  107.                     if (ModifyChild(COLORCHANGE_EDIT, root, i, false)) return(memFullErr);
  108.                     if (part == kBorderColor)
  109.                         mDerefCommon(cobj)->borderColor = rgb2;
  110.                     else
  111.                         mDerefCommon(cobj)->contentColor = rgb2;
  112.                 }
  113.             }
  114.         }
  115.         DoImageDocument(frHndl);
  116.     }
  117.  
  118.     return(noErr);
  119. }
  120.  
  121.  
  122.  
  123.